package com.newtouch.avmarketing.mgr.modules.avmarkrting.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import javax.lang.model.type.NullType;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {
    private int code = ResultCodes.SUCCESS_CODE;
    private String message = "ok";

    private T data = null;

    public static Result<NullType> of() {
        Result<NullType> result = new Result<>();
        return result;
    }

    public static Result<NullType> of(int code, String message) {
        Result<NullType> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <V> Result<V> of(int code, String message, Class<V> resultType) {
        Result<V> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <V> Result<V> of(V t) {
        Result<V> result = new Result<>();
        result.setData(t);
        return result;
    }

    public static <V> Result<V> of(int code, String message, V data) {
        Result<V> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

}
